package com.durian.base.net.monitor;

import androidx.collection.ArrayMap;

/**
 * 说明：HttpMonitor
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019/2/16 10:51
 * <p/>
 * 版本：version 1.0
 */
public class HttpMonitor {

    private static HttpMonitor                                        sHttpMonitor;
    private        ArrayMap<HttpMonitorListener, HttpMonitorListener> mListenerMap;

    private HttpMonitor() {
        if (mListenerMap == null) {
            mListenerMap = new ArrayMap<>();
        }
    }

    public static HttpMonitor get() {
        synchronized (HttpMonitor.class) {
            if (sHttpMonitor == null) {
                sHttpMonitor = new HttpMonitor();
            }
        }
        return sHttpMonitor;
    }

    public void addListener(HttpMonitorListener listener) {
        if (mListenerMap != null && listener != null && !mListenerMap.containsKey(listener)) {
            mListenerMap.put(listener, listener);
        }
    }

    public void removeListener(HttpMonitorListener listener) {
        if (mListenerMap != null && listener != null && mListenerMap.containsKey(listener)) {
            mListenerMap.remove(listener);
        }
    }

    public ArrayMap<HttpMonitorListener, HttpMonitorListener> getMonitorMap() {
        return mListenerMap;
    }
}
